﻿using DLog.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DLog.Config
{
    public class NlogConfig
    {
        /// <summary>
        /// 通过键获得节点的值
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetNodeInnerText(string nodeName)
        {
            string xmlPath = System.AppDomain.CurrentDomain.BaseDirectory + "DLog.config";
            return XMLHelper.GetNode(xmlPath, nodeName).InnerText;
        }
        /// <summary>
        /// 获得Dlog.config文件中Target的值
        /// </summary>
        public static string Target
        {
            get
            {
                if (CacheHelper.Get("Target") == null)
                    CacheHelper.Insert("Target", GetNodeInnerText("Target"));
                return CacheHelper.Get("Target").ToString();
            }
        }//{ get; private set; }
        /// <summary>
        /// 如果是数据库，获得Dlog.config文件中connectionString的值
        /// </summary>
        public static string ConnectionString
        {
            get
            {
                if (CacheHelper.Get("ConnectionString") == null)
                    CacheHelper.Insert("ConnectionString", GetNodeInnerText("ConnectionString"));
                return CacheHelper.Get("ConnectionString").ToString();
            }
        }
    }
}
